var app = getApp();
const WxParse = require('../../../wxParse/wxParse.js');
Page({

  data: {
    week: ['日', '一', '二', '三', '四', '五', '六'],
    // 0：未签，1：已签，2：还未到
    arr: [],
  },
  onLoad: function () {
    var that = this;
    var date = new Date();
    var year = date.getFullYear();
    var months = date.getMonth() + 1;
    that.setData({
      year: year,
      months: months,
    })
    that.dataTime();
  },
  //获取日历排版
  dataTime: function () {
    var that = this;
    var year = that.data.year;
    var months = that.data.months;
    var month = months - 1
    //当前的年月日（格式为 ：年-月-日）
    months = months < 10 ? '0' + months : months;
    var monthHead = year + '-' + months;
    //第一天星期几
    var firstDay = new Date(year, month, 1).getDay();
    that.setData({
      monthHead: monthHead,
      firstDay: firstDay,
    })
    that.getCon();
  },
  getCon: function () { //请求月份的数据
    let that = this;
    let time = that.data.year + '-' + that.data.months
    // 请求当月数据
    wx.showLoading({
      title: '加载中...',
    })
    app.request('sign/index', { time },'GET',false,function(res){
      that.setData({
        pageShow: true,
        arr: res.data.data.sign.date || [],
        user: res.data.data.user || {},
        is_sign: res.data.data.sign.is_sign,
        total_day: res.data.data.sign.total_day || 0,
        editor: WxParse.wxParse('editor', 'html', res.data.data.sign.rule, that, 5),
      })
    })
  },
  sign(){
    let that = this;
    app.request('sign/dosign',{},'GET',true,function(res){
      wx.showToast({
        title: '签到成功',
        mask: true,
      })
      that.dataTime();
    })
  },
  prev(e) {
    var that = this;
    var year = that.data.year;
    var months = that.data.months;
    if (months > 1) {
      months--
    } else {
      months = 12;
      year--
    }
    that.setData({
      year: year,
      months: months,
    })
    that.dataTime();
  },
  next(e) {
    var that = this;
    var year = that.data.year;
    var months = that.data.months;
    if (months < 12) {
      months++
    } else {
      months = 1;
      year++
    }
    that.setData({
      year: year,
      months: months,
    })
    that.dataTime();
  },
  noticeShow(e){
    let that = this;
    that.setData({
      maskShow: true,
      noticeShow: true,
    })
  },
  maskHide() {
    let that = this;
    that.setData({
      maskShow: false,
      noticeShow: false,
    })
  },
  onShareAppMessage: function () {
    return{
      path: '/pages/index/index'
    }
  }
})